function RequestRecentPosts() {
    var prefs = new gadgets.Prefs();
    var feed_url = prefs.getString("feed");
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] =
	gadgets.io.ContentType.DOM;
    params[gadgets.io.RequestParameters.REFRESH_INTERVAL] = 0;
    gadgets.io.makeRequest(feed_url, ProcessPosts, params);
}

function ProcessPosts(obj) {
    var html = '';
    var now = new Date();
    var entries = XMLChildrenByNodeName(obj.data.documentElement, 'entry');
    var prefs = new gadgets.Prefs();
    entries.length = prefs.getString("count");
    var base_url = CalculateSiteURL('/news/');
    for (var i = 0; i < entries.length; ++i) {
	var entry = entries[i];
	var post_url = base_url + XMLChildrenByNodeName(entry, 'sites:pageName')[0].textContent;
	var title = XMLChildrenByNodeName(entry, 'title')[0].textContent;
	var author = XMLChildrenByNodeName(XMLChildrenByNodeName(entry, 'author')[0], 'name')[0].textContent;
	author = 'REC';
	var snippet = XMLChildrenByNodeName(entry, 'content')[0].textContent;
	if (snippet.length > 200) snippet = snippet.substr(0, 200) + '...';
	var img = entry.getElementsByTagName('img')[0];
	var image = (img == null)?'':'<img class="thumb" src="' + img.src + '" />';
	var timestamp = new Date(XMLChildrenByNodeName(entry, 'published')[0].textContent);
	html += '<div class="article"><h4><a href="' + post_url +
	    '" target="_top">' + title +
	    '</a></h4><p>' + image + snippet +
	    '</p><p>By <span class="author">' + author +
	    '</span>, <span pubdate="" class="time">' + TextifyAge(now, timestamp)
	    '</span></p></div>';
    }
    html += '<p><a href="' + CalculateSiteURL("/news") +
	'" class="jump" target="_top">More news</a></p>';
    document.getElementById('post_list').innerHTML = html;
    if (gadgets.window != null) gadgets.window.adjustHeight();
}
